﻿using System;
using System.Collections.Generic;
using System.Xml;

namespace HYCodeBase.XmlUtility
{
	public class XmlNodeInformationBean
	{
		public string StrNodeName
		{
			get
			{
				return this.m_strNodeName;
			}
			set
			{
				this.m_strNodeName = value;
			}
		}

		public string StrInnerText
		{
			get
			{
				return this.m_strInnerText;
			}
			set
			{
				this.m_strInnerText = value;
			}
		}

		public List<KeyValuePair<string, string>> LstKvpAttribute
		{
			get
			{
				return this.m_lstKvpAttribute;
			}
			set
			{
				this.m_lstKvpAttribute = value;
			}
		}

		public List<XmlNodeInformationBean> LstSubNodes
		{
			get
			{
				return this.m_lstSubNodes;
			}
			set
			{
				this.m_lstSubNodes = value;
			}
		}

		public XmlNode ToXmlNode(ref XmlDocument inputDoc)
		{
			XmlDocument xmlDocument = inputDoc;
			XmlNode xmlNode = null;
			try
			{
				xmlNode = xmlDocument.CreateNode(XmlNodeType.Element, this.StrNodeName, null);
				if (!string.IsNullOrEmpty(this.StrInnerText))
				{
					xmlNode.InnerText = this.StrInnerText;
				}
				foreach (KeyValuePair<string, string> keyValuePair in this.LstKvpAttribute)
				{
					XmlAttribute xmlAttribute = xmlDocument.CreateAttribute(keyValuePair.Key);
					xmlAttribute.Value = keyValuePair.Value;
					xmlNode.Attributes.Append(xmlAttribute);
				}
				foreach (XmlNodeInformationBean xmlNodeInformationBean in this.m_lstSubNodes)
				{
					XmlNode xmlNode2 = xmlNodeInformationBean.ToXmlNode(ref inputDoc);
					if (xmlNode2 != null)
					{
						xmlNode.AppendChild(xmlNode2);
					}
				}
			}
			catch (Exception)
			{
				xmlNode = null;
			}
			return xmlNode;
		}

		public static XmlNodeInformationBean ReadXmlNode(XmlNode inputNode)
		{
			XmlNodeInformationBean xmlNodeInformationBean = null;
			try
			{
				xmlNodeInformationBean = new XmlNodeInformationBean();
				xmlNodeInformationBean.StrNodeName = inputNode.Name;
				if (inputNode.ChildNodes != null)
				{
					foreach (object obj in inputNode.ChildNodes)
					{
						if (obj is XmlText)
						{
							if (xmlNodeInformationBean.StrInnerText == null)
							{
								xmlNodeInformationBean.StrInnerText = string.Empty;
							}
							xmlNodeInformationBean.StrInnerText += (obj as XmlText).Value;
						}
					}
				}
				List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
				if (inputNode.Attributes != null)
				{
					foreach (object obj2 in inputNode.Attributes)
					{
						XmlAttribute xmlAttribute = (XmlAttribute)obj2;
						list.Add(new KeyValuePair<string, string>(xmlAttribute.Name, xmlAttribute.Value));
					}
					xmlNodeInformationBean.LstKvpAttribute = list;
				}
				if (inputNode.ChildNodes != null)
				{
					foreach (object obj3 in inputNode.ChildNodes)
					{
						if (obj3 != null && obj3 is XmlNode)
						{
							XmlNodeInformationBean xmlNodeInformationBean2 = XmlNodeInformationBean.ReadXmlNode(obj3 as XmlNode);
							if (xmlNodeInformationBean2 != null)
							{
								xmlNodeInformationBean.LstSubNodes.Add(xmlNodeInformationBean2);
							}
						}
					}
				}
			}
			catch (Exception)
			{
				xmlNodeInformationBean = null;
			}
			return xmlNodeInformationBean;
		}

		private string m_strNodeName = string.Empty;

		private string m_strInnerText = string.Empty;

		private List<KeyValuePair<string, string>> m_lstKvpAttribute;

		private List<XmlNodeInformationBean> m_lstSubNodes = new List<XmlNodeInformationBean>();
	}
}
